<template>
<!--      <div id="components-layout-demo-basic">-->
<!--        <a-layout>-->
          <a-layout-header>
            <div>
              <a-input v-model="keyword" placeholder="请输入关键字" style="width:200px;display:inline-block" />
              <a-button type="primary" style="display:inline-block" @click="queryBlog">
                确定
              </a-button>
              <router-link to="/EditBlog" target="_blank" style="font-family: '楷体';font-size:18px;margin-left:10px;">写博客</router-link>

              <div class="userInfo" style="float: right;display: inline-block">
                <a-avatar :src=headUrl />
                <a-dropdown>
                  <a class="ant-dropdown-link">
                    {{username}}
                    <a-icon type="down" />
                  </a>
                  <a-menu slot="overlay">
                    <a-menu-item>
                      <a @click="logout">退出登录</a>
                    </a-menu-item>

                    <a-menu-item>
                      <router-link to="/UpdatePass" target="_blank"><span>修改密码</span></router-link>
                    </a-menu-item>

                  </a-menu>
                </a-dropdown>
              </div>
            </div>


          </a-layout-header>
<!--        </a-layout>-->
<!--      </div>-->
</template>

<script>
    import msgTip from '../msgTip'
    export default {
        name: "Header",
        data () {
            return {
                keyword:"",
                username:"",
                // headUrl:"https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
                headUrl:require('@/assets/bianji.png'),
            }
        },
        methods:{
            /**
             * 退出登录
             */
            logout(){
                let username = localStorage.getItem("username");
                if (username){
                    logout({username:username}).then(res=>{
                        console.log(res);
                        this.checkStatus(res.data.code);
                        if(res.data.code==200){
                            localStorage.removeItem("username");
                            localStorage.removeItem("uid");
                            this.$message.success("退出成功")
                        }else{
                            this.$message.success("操作失败")
                        }
                    })
                }
            },

            /**
             * 编辑
             */
            editBlog (id) {
                //阻止冒泡
                window.event? window.event.cancelBubble = true : e.stopPropagation();
                this.detailBlog(id,"edit");
            },



            /**
             * 关键字查找
             */
            queryBlog() {
                let keyword = {
                    keyword:this.keyword
                };

                getBlogByKeyword(keyword).then((res)=>{
                    this.checkStatus(res.data.code);
                    this.init(res.data.list);
                })
            },

        },

        mounted() {
            this.username = this.getCookie("curUsername");
        }
    }
</script>

<style scoped>

</style>
